// 全局变量
var mainColor = '#FFD668';
var searchTypesLit;
var COMPREHENSIVE_DISPLAY = (function() {
	//获取页面统计信息
	function loadChartInfo() {
		$.ajax({
			type: "POST",
			url: "invs_home_page.do/load_display_login",
			data: {datePatten : 1},
			success: function(data) {
				WeKnow.closeLoading();
				if (!WeKnow.filterAjaxResult(data)) return false; // session过期check

				if (data.errorcode == 0) {
					var chartInfo = data.chartInfo;
					// searchTypesLit = chartInfo.searchTypes;
					setSelectpickerOptions(chartInfo.searchTypes);
					//机构总数
					drawInstitutionsTotal(chartInfo.quantity, chartInfo.total);
					//页面的amount赋值
					getAmount(chartInfo);
					//处方违规类型（左上树状图）
					drawTypeBar(chartInfo.prescriptionSupervision.presDailyByType);
					//处方违规数趋势（左上折线图）
					drawTrendLine(chartInfo.prescriptionSupervision.violateTimeLine);
					//卫生消毒分布（右上极坐标图）
					drawdisinfectPolar(chartInfo.accountSupervision.accountType);
					//质控评分分布
					drawQualityControlPie(chartInfo.qualityControl);
					//信用评价分布
					drawfeedbackBar(chartInfo.feedback);
					//社会监督（中底部）
					drawSocietyLine(chartInfo.societyVision.satisfactionList);
					//地图标点
					loadMarker(chartInfo.mapInfo);
				} else if (data.errorcode == -1 ){
					WeKnow.errorMsg( data.errMsg );
				} else {
					WeKnow.systemMsg('查询失败，请重新登录');
				}
			}
		});
	}

	//机构总数
	function drawInstitutionsTotal(invs, total) {
		if(invs == undefined || invs.length == 0 ) {
			invs = 0;
		}

		if(invs == undefined || invs.length == 0 ) {
			total = 0;
		}

		//清空
		document.getElementById("institutionsTotal").innerHTML = "";

		var numbers =  invs.toString();
		var length = total >=  invs ? total.toString().length : invs.toString().length;

		for(var i=0; i < 3-length; i++) {
			$("#institutionsTotal").append(
				"<span class='middleAboveNumFont'>" + 0 + "</span>"
			);
		}

		for(var i=0; i < length; i++) {
			$("#institutionsTotal").append(
				"<span class='middleAboveNumFont'>" + numbers[i] + "</span>"
			);
		}

		$("#institutionsTotal").append(
			"<span class='middleAboveFont'>" + '&nbsp;|&nbsp;' + "</span>"
		);

		numbers = total.toString();
		for(var i=0; i < 3-length; i++) {
			$("#institutionsTotal").append(
				"<span class='middleAboveNumFont'>" + 0 + "</span>"
			);
		}

		for(var i=0; i < length; i++) {
			$("#institutionsTotal").append(
				"<span class='middleAboveNumFont'>" + numbers[i] + "</span>"
			);
		}
	}

	//处方违规类型（左上树状图）
	function drawTypeBar(data) {
		var valueData = [
			{name:"医疗机构超范围诊疗", value:0},{name:"医师超范围开具处方", value:0},{name:"多个执业地点同时开具处方", value:0},
			{name:"无处方权开具处方", value:0},{name:"执业助理医师开具处方", value:0},{name:"未经批准开具精麻药品", value:0},
			{name:"未经培训合格开具抗菌药物", value:0}, {name:"越级使用抗菌药物", value:0},{name:"未经药师调剂药品", value:0},
			{name:"不合理用药", value:0},{name:"非执业点开处方", value:0},
		];

		if (data != undefined && data != null && data.length > 0) {
			for (var i=0; i < data.length; i++) {
				switch (data[i].type) {
					case "810001":
						valueData[0].value = data[i].value;
						break;
					case "810002":
						valueData[1].value = data[i].value;
						break;
					case "810003":
						valueData[2].value = data[i].value;
						break;
					case "820001":
						valueData[3].value = data[i].value;
						break;
					case "820002":
						valueData[4].value = data[i].value;
						break;
					case "820003":
						valueData[5].value = data[i].value;
						break;
					case "820004":
						valueData[6].value = data[i].value;
						break;
					case "820005":
						valueData[7].value = data[i].value;
						break;
					case "830001":
						valueData[8].value = data[i].value;
						break;
					case "840001"://包含所有84开头
						valueData[9].value = data[i].value;
						break;
					case "850001":
						valueData[10].value = data[i].value;
						break;
				}
			}
			valueData.sort(sortValue);
		}

		var nameData = [];
		for (var j=0; j < valueData.length; j++) {
			nameData.push(valueData[j].name);
		}

		// 1. 实例化对象
		var myChart = echarts.init(document.querySelector("#prescriptionBar"));
		// 2. 指定配置项和数据
		option = {
			color: [mainColor],
			xAxis : [
				{
					type : 'value',
					show: false,
					axisLine: {
						show: false
					},
					axisTick:{
						show: false
					},
					splitLine: {
						show: false
					}
				}
			],
			yAxis : [
				{
					min: 0,
					minInterval: 0,
					type : 'category',
					data : nameData,
					axisLabel: {
						show: true,
						textStyle: {
							color: 'rgb(255,255,255,0.9)',
							fontSize:fontChart(0.15)
						}
					},
					axisLine:{
						show: false,
					},
					axisTick:{
						"show":false
					},
					splitLine: {
						"show": false
					}
				}
			],
			grid: {
				left: '1%',
				right: '5%',
				bottom: '5%',
				top: '7%',
				containLabel: true
			},
			series : [
				{
					type:'bar',
					barMinHeight: fontChart(0.0125),
					barWidth: fontChart(0.1875),
					itemStyle : {
						normal: {
							label : {
								show: true,
								position: 'right',
							},
						}
					},
					data:valueData
				}
			]
		};
		// 3. 配置项和数据给我们的实例化对象
		myChart.setOption(option);
		// 4. 当我们浏览器缩放的时候，图表也等比例缩放
		window.addEventListener("resize", function() {
			// 让我们的图表调用 resize这个方法
			myChart.resize();
		});
	};

	function sortValue(a, b) {
		return a.value - b.value;
	}

	//处方违规数趋势（左上折线图）
	function drawTrendLine(data) {
		if (data.length == 0) {
			return;
		} else {
			var nameData = [];
			var valueData = [];
			var year = (new Date()).getFullYear();
			var cWeek = data.length > 0 ? data[0].name : '';
			for(var i=data.length; i > 0; i--){
				var temp = cWeek >= data[i-1].name ? year : year-1;
				data[i-1].name = temp.toString().substring(2,4) + '年' + data[i-1].name + '周';
				nameData.push(data[i-1].name);
				valueData.push(data[i-1]);
			}
		}
		// 基于准备好的dom，初始化echarts实例
		var myChart = echarts.init(document.querySelector("#prescriptionLine"));
		// 2. 指定配置和数据
		option = {
			title: {
				x: 'left',
				y: 'top',
				text:"违规处方数",
				textStyle: {
					fontSize: fontChart(0.15),
					color: mainColor
				},
			},
			tooltip: {
				trigger: "axis",
				axisPointer: {
					lineStyle: {
						color: mainColor
					}
				}
			},
			grid: {
				left: fontChart(0.375),
				top: fontChart(0.3125),
				right: fontChart(0.25),
				bottom: fontChart(0.1875),
				containLabel: true
			},
			xAxis: [
				{
					type: "category",
					boundaryGap: false,
					axisLine: {
						lineStyle: {
							color: mainColor,
						},
					},
					axisTick: {
						show: false
					},
					splitLine: {
						show: false
					},
					data: nameData,
					axisLabel: {
						margin: fontChart(0.2),
						interval:0, //坐标刻度之间的显示间隔，默认就可以了（默认是不重叠）
						rotate: 30,   //调整数值改变倾斜的幅度（范围-90到90）
						textStyle: {
							color: mainColor,
							fontSize: fontChart(0.15)
						}
					},
					grid: {
						left: '0%',
						bottom:'90%'
					},
				},
				{
					axisPointer: { show: false },
					axisLine: { show: false },
					position: "bottom",
					offset: 20
				}
			],
			yAxis: [
				{
					type: "value",
					min: 0,
					minInterval: 1,
					axisTick: { show: false },
					axisLine: {
						lineStyle: {
							color: mainColor,
						},
					},
					axisLabel: {
						textStyle: {
							color: mainColor,
							fontSize: fontChart(0.15)
						}
					},
					splitLine: {
						show: false
					}
				}
			],
			series: [
				{
					name: "",
					type: "line",
					smooth: true,
					symbol: "circle",
					symbolSize: 0,
					showSymbol: false,
					lineStyle: {
						normal: {
							color: mainColor,
							width: 2
						}
					},
					areaStyle: {
						normal: {
							color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
								offset: 0,
								color: mainColor
							}, {
								offset: 1,
								color: 'rgba(255,214,104,0.1)'
							}]),
						}
					},
					itemStyle: {
						normal: {
							color: mainColor,
							borderColor: "rgba(221, 220, 107, .1)",
							borderWidth: 12
						}
					},
					data: valueData
				}
			]
		};
		// 3. 把配置和数据给实例对象
		myChart.setOption(option);

		window.addEventListener("resize", function() {
			myChart.resize();
		});
	};

	//卫生台账覆盖率（右上极坐标图）
	function drawdisinfectPolar(data) {

		var valueData = [
			{'name':'器械消毒', 'value':0},{'name':'场所消毒', 'value':0},{'name':'医疗废弃物', 'value':0},
			{'name':'污水检测报告', 'value':0},{'name':'余氯日检', 'value':0},{'name':'器械消毒报告', 'value':0}
		];

		var nameData = [];
		for(var i=0; i < valueData.length;i++){
			nameData.push(valueData[i].name);
		}

		if (data != undefined) {
			if (data.t101 != undefined) {
				valueData[0] = data.t101;
			}
			if (data.t102 != undefined) {
				valueData[1] = data.t102;
			}
			if (data.t201 != undefined) {
				valueData[2] = data.t201;
			}
			if (data.t301 != undefined) {
				valueData[3] = data.t301;
			}
			if (data.t302 != undefined) {
				valueData[4] = data.t302;
			}
			if (data.t303 != undefined) {
				valueData[5] = data.t303;
			}
		}

		// 1. 实例化对象
		var myChart = echarts.init(document.getElementById("disinfectPie"));
		// 2. 指定配置项和数据
		option = {
			tooltip: {
				trigger: 'item',
			},
			angleAxis: {//极坐标系的角度轴
				boundaryGap: ['50%', '50%'],
				type: 'category',
				startAngle: 90,
				splitNumber: 24, //坐标轴分割段数
				axisLine: { //坐标轴轴线设置
					lineStyle: {
						color: 'rgba(255, 255, 255, 0.6)',
					}
				},
				axisTick: { //坐标轴刻度设置
					show: true,
					interval: 2,
				},
				splitLine: { //分割线设置
					show: false,
				},
				axisLabel: { //刻度标签设置
					textStyle: {
						color: '#01FFFF'
					}
				},
				data: nameData
			},
			radiusAxis: {
				min: 0,
				minInterval: 1,
				axisLine: { //坐标轴轴线设置
					show: true,
					lineStyle: {
						color: 'rgba(255, 255, 255, 0.6)'
					}
				},
				axisTick: { //坐标轴刻度设置
					show: true
				},
				axisLabel: { //刻度标签设置
					margin: 5, //刻度与坐标轴之间的距离
					textStyle: {
						color: '#01FFFF'
					}
				},
			},
			polar: {
				center: ['50%', '50%'],
			},
			series: [{
				type: 'bar',
				data: valueData,
				coordinateSystem: 'polar',
				lineStyle: {
					normal: {
						color: 'rgba(255, 255, 255, 0.9)'
					}
				},
				itemStyle: {
					normal: {
						color: '#01FFFF'
					}
				},
				animationDuration: 2000
			}],
		};

		// 3. 配置项和数据给我们的实例化对象
		myChart.setOption(option);
		// 4. 当我们浏览器缩放的时候，图表也等比例缩放
		window.addEventListener("resize", function() {
			// 让我们的图表调用 resize这个方法
			myChart.resize();
		});
	}

	//社会监督
	function drawSocietyLine(data) {
		if (data == undefined) {
			return;
		}

		if (data.count0 != undefined) {
			$('#societyLevel0').html(data.count0 + '%');
		}

		if (data.count1 != undefined) {
			$('#societyLevel1').html(data.count1 + '%');
		}

		if (data.count2 != undefined) {
			$('#societyLevel2').html(data.count2 + '%');
		}
	}

	//质控评分分布
	function drawQualityControlPie(data) {
		if (data.length == 0) {
			return;
		} else {
			var nameData = [];
			var valueData = [];
			for(i=0;i<data.length;i++){
				nameData.push(data[i].name);
				valueData.push(data[i]);
			}
		}
		// 1. 实例化对象
		var myChart = echarts.init(document.querySelector("#qualityControlPie"));
		// 2. 指定配置项和数据
		option = {
			tooltip : {
				trigger: 'item',
				formatter: "{b}<br/>{c} ({d}%)"
			},
			color: [
				mainColor,
				"#217eff",
			],
			series : [
				{
					name:'',
					type:'pie',
					center: ["50%", "45%"],
					radius : ['40%', '60%'],
					labelLine : {
						show : true,
						normal:{
							length: fontChart(0.125),  // 改变标示线的长度
							lineStyle: {
								color: "rgb(255,255,255,0.9)"  // 改变标示线的颜色
							}
						},
					},
					itemStyle : {
						normal : {
							label : {
								show : true,
								formatter: "{b}\n{c} ({d}%)",
								textStyle: {
									color: "rgb(255,255,255,0.9)",  // 改变标示文字的颜色
									fontSize : fontChart(0.15)
								}
							},
							labelLine : {
								show : true
							}
						}
					},
					color: ['#F2828E', '#FFFF01', '#558FF0'],
					data:valueData
				}
			]
		};
		// 3. 配置项和数据给我们的实例化对象
		myChart.setOption(option);
		// 4. 当我们浏览器缩放的时候，图表也等比例缩放
		window.addEventListener("resize", function() {
			// 让我们的图表调用 resize这个方法
			myChart.resize();
		});
	};

	//信用评价分布
	function drawfeedbackBar(data) {
		if (data == null || data.length == 0) {
			return;
		}

		var nameData = [];
		for(var i=0; i < data.length; i++){
			nameData.push(data[i].name);
		}

		// 1. 实例化对象
		var myChart = echarts.init(document.querySelector("#feedbackBar"));
		// 2. 指定配置项和数据
		option = {
			title: {
				subtext: '机构数',
				subtextStyle: {
					color: 'rgb(255, 255, 255, 0.9)',
				}
			},
			/*grid:{
				x: 40,
				y: 60,
				x2: 15,
				y2: 25,
			},*/
			tooltip : {
				trigger: 'axis'
			},
			calculable : true,
			xAxis : [
				{
					type : 'category',
					data : nameData,
					axisLine: {
						lineStyle: {
							color: '#1EA3A7'
						}
					},
					splitLine: {
						show: false
					},
					axisTick:{
						show:false
					},
					axisLabel: {
						textStyle: {
							fontSize: fontChart(0.15),
							color: 'rgb(255, 255, 255, 0.9)'
						}
					}
				}
			],
			yAxis : [
				{
					type : 'value',
					minInterval: 1,
					axisLine: {
						lineStyle: {
							color: '#1EA3A7'
						}
					},
					splitLine: {
						show: false
					},
					axisTick:{
						show:false
					},
					axisLabel: {
						textStyle: {
							fontSize: fontChart(0.15),
							color: 'rgb(255, 255, 255, 0.9)'
						},
					}
				}
			],
			series : [
				{
					name:'机构数',
					type:'bar',
					data: data,
					itemStyle: {
						normal: {
							color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
								offset: 0,
								color: '#F2828E'
							}, {
								offset: 1,
								color: '#558FF0'
							}]),
						}
					},
					barWidth: 40,
				}
			]
		};

		// 3. 配置项和数据给我们的实例化对象
		myChart.setOption(option);
		// 4. 当我们浏览器缩放的时候，图表也等比例缩放
		window.addEventListener("resize", function() {
			// 让我们的图表调用 resize这个方法
			myChart.resize();
		});
	};
	//数量数据页面赋值
	function getAmount(data) {
		/***诊疗行为部分**/
		//电子处方
		$("#prescriptionAmount").html(data.prescriptionSupervision.allPresCnt);
		//违规处方
		$("#violatePrescription").html(data.prescriptionSupervision.errorPresCnt);
		//违规率
		$('#violateRate').html(data.prescriptionSupervision.allPresCnt == 0 ? '-':(data.prescriptionSupervision.errorPresCnt*100/data.prescriptionSupervision.allPresCnt).toFixed(2)+"%");
		//已处理
		$('#prescriptionHandle').html(data.prescriptionSupervision.errorPresProcessedCnt);
		//处理率
		$('#prescriptionHandleRate').html(data.prescriptionSupervision.errorPresCnt == 0 ? '-':(data.prescriptionSupervision.errorPresProcessedCnt*100/data.prescriptionSupervision.errorPresCnt).toFixed(2)+"%");

		/***自查自律**/
		//应自查数
		$('#examinationAmount').html(data.quantity);
		//未全面自查数
		$('#noExaminationAmount').html(data.quantity-data.autonomyExamination.incompleteComprehensiveInspections);
		//未专业自查数
		$('#noSpeciallyAmount').html(data.quantity-data.autonomyExamination.incompleteProfessionalInspections);
		//未全面自查数占比
		$('#noExaminationRate').html(data.autonomyExamination.inspections == 0 ? '0%':(data.autonomyExamination.incompleteComprehensiveInspections*100/data.autonomyExamination.inspections).toFixed(2)+"%");
		//未专业自查数占比
		$('#noSpeciallyRate').html(data.autonomyExamination.inspections == 0 ? '0%':(data.autonomyExamination.incompleteProfessionalInspections*100/data.autonomyExamination.inspections).toFixed(2)+"%");

		/***卫生消毒**/
		//电子台账
		$('#electronicDisinfect').html(data.accountSupervision.allActionCnt);
		//异常台账
		$('#illegalDisinfect').html(data.accountSupervision.errorActionCnt);
		//异常率
		$('#illegalRate').html(data.accountSupervision.allActionCnt == 0 ? '-':(data.accountSupervision.errorActionCnt*100/data.accountSupervision.allActionCnt).toFixed(2)+"%");
		//已处理
		$('#disinfectHandle').html(data.accountSupervision.errorActionProcessedCnt);
		//处理率
		$('#disinfectHandleRate').html(data.accountSupervision.errorActionCnt == 0 ? '-':(data.accountSupervision.errorActionProcessedCnt*100/data.accountSupervision.errorActionCnt).toFixed(2)+"%");

		/***社会监督**/
		//无扫码记录机构
		$('#noQrcodeScanning').html(data.societyVision.noQrcodeScanning);
		//公众评价书<3
		$('#fewPublicComments').html(data.societyVision.fewPublicComments);
	}
	//获取坐标点在地图上标注出来
	function loadMarker(data) {
		if (data == undefined || data == null) {
			return;
		}
		MY_MAP.loadDisplayMarker(data);
	}

	//自适应字体大小
	function fontChart(res) {
		//获取到屏幕的宽度
		var clientWidth =
			window.innerWidth ||
			document.documentElement.clientWidth ||
			document.body.clientWidth;
		if (!clientWidth) return; //报错拦截：
		var fontSize = 80 * (clientWidth / screen.width);
		return res * fontSize;
	}

	//设置时间
	function setDateTime(){
		var t = null;
		t = setTimeout(time, 1000); //開始运行
		function time() {
			clearTimeout(t); //清除定时器
			dt = new Date();
			var weekDay = new Array("日", "一", "二", "三", "四", "五", "六");
			var y = dt.getFullYear();
			var mt = dt.getMonth() + 1<10?'0'+(dt.getMonth()+ 1):dt.getMonth()+ 1;
			var day = dt.getDate()<10?'0'+dt.getDate():dt.getDate();
			var h = dt.getHours()<10?'0'+dt.getHours():dt.getHours(); //获取时
			var m = dt.getMinutes()<10?'0'+dt.getMinutes():dt.getMinutes(); //获取分
			var s = dt.getSeconds()<10?'0'+dt.getSeconds():dt.getSeconds(); //获取秒
			var week = dt.getDay();
			document.getElementById("showTime").innerHTML =
				"<span style='font-size:0.2rem;margin-right: 0.3rem;letter-spacing: 0.01rem;'>"+y+"年"+mt+"月"+day+"日"+"</span>" +
				"<span style='float:right;font-size:0.2rem;margin-right: 0.3rem;letter-spacing: 0.02rem;'>星期"+weekDay[week]+"</span>" +
				"<span style='font-size:0.375rem;letter-spacing: 0.01rem;'>"+h+":"+m+":"+s+"</span>";
			t = setTimeout(time, 1000); //设定定时器，循环运行
		}
	}

	//页面刷新
	function refreshWindow(){
		COMPREHENSIVE_DISPLAY.setDateTime();
		COMPREHENSIVE_DISPLAY.loadChartInfo();
	}

	function setSelectpickerOptions(data) {
		setOptionsCommon('street', data.district);
		setOptionsCommon('industry', data.industry);
		setOptionsCommon('level', data.level);
		setOptionsCommon('economic', data.economic);
		setOptionsCommon('ownership', data.ownership);
		$('.selectpicker').selectpicker('refresh');
	}

	function setOptionsCommon(name, data) {
		if (data == undefined) {
			return;
		}

		if (name == 'economic') {
			document.getElementById("economicOption0").textContent = "公立 (" + data.publicCnt + ")";
			document.getElementById("economicOption1").textContent = "民营 (" + data.privateCnt + ")";
		} else {
			var ele = $("#"+name + "Select");
			for (var i=0; i < data.length; i++) {
				var id = name + 'Option' + data[i].id;
				var element = document.getElementById(id);
				if (element) {
					element.textContent =  data[i].name + " (" + data[i].value + ")";
				} else {
					ele.append("<option value=" + data[i].id + " id=" + id + ">" + data[i].name + " (" + data[i].value + ")</option>");
				}
			}
		}
	}

	function getParamsSearch(searchKey, currentPage, limit) {
		var params = {};

		params.searchKey = searchKey;
		params.currentPage = currentPage;
		params.limit = limit;
		params.street = $('#streetSelect').find("option:selected").val();
		params.industry = $('#industrySelect').find("option:selected").val();
		params.economic = $('#economicSelect').find("option:selected").val();
		params.level = $('#levelSelect').find("option:selected").val();
		params.ownership = $('#ownershipSelect').find("option:selected").val();

		return params;
	}

	function searchLoad(target, searchKey, currentPage) {
		var limit = 10;
		var $that = target;
		var params = getParamsSearch(searchKey, currentPage, limit);
		$.ajax({
			type: "POST",
			url: "invs_home_page.do/dispaly_search_login",
			data: params,
			success: function(data) {
				WeKnow.closeLoading();
				if (!WeKnow.filterAjaxResult(data)) return false; // session过期check

				if (data.errorcode == 0) {
					var institutionList = data.institutionList;
					var total = data.total;
					$('#searchList').empty();
					if (institutionList == null || institutionList.length == 0 ) {
						//
					} else {

						$(institutionList).each(function (idx, g) {
							$((function () {
								var e = '';
								e += '<tr class="search-tr">';
								e += '<td class="search-td">' + g.name + '</td>';
								e += '<td style="display:none">' + g.id + '</td>';
								e += '</tr>';
								return e;
							})()).appendTo($('#searchList')).on('click', function () {
								$('input#displaySearch').val(g.name);
								$('button#institutionDetails').attr("data-institutionname", g.name);
								$('button#institutionDetails').attr("data-institutionid", g.id);
								toLogin();
							});
						});
					}

					// $('.selectpicker').selectpicker('refresh');

					if (total > limit) {
						$('div.layui-table-page').show();
					} else {
						$('div.layui-table-page').hide();
					}

					layui.use('laypage', function(){
						var laypage = layui.laypage;
						//执行一个laypage实例
						laypage.render({
							elem: 'searchPagination',
							count: total,
							limit: limit,
							curr: currentPage,
							// theme: 'rgb(46,76,255)',
							jump: function (obj, first) { //obj为当前页的属性和方法，第一次加载first为true
								//非首次加载 do something
								if (!first) {
									//清空以前加载的数据
									$('#searchList').empty();
									//调用加载函数加载数据
									COMPREHENSIVE_DISPLAY.searchLoad($that, searchKey, obj.curr);
								}
							}
						});
					});

				} else if (data.errorcode == -1 ) {
					WeKnow.errorMsg( data.errMsg );
				} else {
					WeKnow.systemMsg('查询失败，请重新登录');
				}
			}
		});
	}

	return {
		setDateTime: setDateTime,
		loadChartInfo:loadChartInfo,
		refreshWindow: refreshWindow,
		searchLoad: searchLoad,
	}
})();

//跳转登录页面
function toLogin() {
	// window.open("login");
	WeKnow.submit(
		'login'
	);
}

//自适应字体大小
function fontChart(res) {
	//获取到屏幕的宽度
	var clientWidth =
		window.innerWidth ||
		document.documentElement.clientWidth ||
		document.body.clientWidth;
	if (!clientWidth) return; //报错拦截：
	var fontSize = 80 * (clientWidth / screen.width);
	return res * fontSize;
}

$(document).ready(function() {
	//初始化地图
	MY_MAP.initMap("comprehensive_display");

	//加载数据
	WeKnow.loading();
	COMPREHENSIVE_DISPLAY.refreshWindow();
	WeKnow.closeLoading();

	//定时刷新
	setInterval("COMPREHENSIVE_DISPLAY.refreshWindow();",10000);

	$('#economicSelect, #ownershipSelect, #levelSelect').selectpicker({
		width: fontChart(1.5)
	});

	$('#industrySelect, #streetSelect').selectpicker({
		width: fontChart(2)
	});

	$('.selectpicker').on('change',function(){
		$("input#displaySearch").trigger("click");
	});

	$("#displayTologin").on('click',function () {
		$("input#displaySearch").trigger("click");
	});

	var autoSearchDisplay;
	$('input#displaySearch').on('input click', function () {

		if (document.getElementById("searchMenu").style.display == 'none') {
			document.getElementById("searchMenu").style.display = 'inline';
		}

		if ($("#searchMenu").is(":hidden")) {
			$("#searchMenu").show();
			$(document).one("click",function () {
				$("#searchMenu").hide();
			});
			e.stopPropagation();
		}

		if (autoSearchDisplay) clearTimeout(autoSearchDisplay);

		var $that = $(this);
		var searchKey = $.trim($that.val());
		// if (searchKey.length) {
		autoSearchDisplay = setTimeout(COMPREHENSIVE_DISPLAY.searchLoad($that, searchKey, 1), 500);
		// }
	});

	$("#container, div[class$='Chart']").on('click', function(e) {
		if (document.getElementById("searchMenu").style.display == 'inline') {
			document.getElementById("searchMenu").style.display = 'none';
		}
	});

});
